#include<bits/stdc++.h>
#define int long long
#define ls(x) ((x)*2)
#define rs(x) ((x)*2+1)
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define rep(i,  b) for(int i=1,i##end=b;i<=i##end;i++)
using namespace std;
const int N=1e6+5,base=999983,Mod=998244353;
const int base1=233,Mod1=998244353;
const int base2=999983,Mod2=1e9+7;
//char buf[(1<<21)+5],*p1,*p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline void chmx(int &x,int y){(x<y)&&(x=y);}
inline void chmn(int &x,int y){(x>y)&&(x=y);}
inline void Add(int &x,int y){(x=x+y+Mod)%=Mod;}
inline int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?-x:x;
}
void print(int n){
    if(n<0){
        putchar('-');
        n*=-1;
    }
    if(n>9) print(n/10);
    putchar(n%10+'0');
}
map<pair<int,int>,int>mp;
int n;
int a[N];
int gg[N]; 
int ans=0;
void dfs(int x){
	if(x==n+1){
		int res=1;
		int hsh1=0,hsh2=0;
		For(i,1,n){
			int c=(a[i]+gg[(i+n-2)%n+1]-gg[i]);
			res=res*c;
			hsh1=hsh1*base1+c;
			hsh1%=Mod1;
			hsh2=hsh2*base2+c;
			hsh2%=Mod2;
			res%=Mod;
//			cout<<(a[i]+gg[(i+n-2)%n+1]-gg[i])<<" ";
		}
//		puts("");
//		cout<<res<<endl;
if(mp[{hsh1,hsh2}]) return;
		mp[{hsh1,hsh2}]=1;
		ans+=res;
		ans%=Mod;
		return ;
	}
	For(i,0,a[x]){
		gg[x]=i;
		dfs(x+1);
		gg[x]=0;
	}
}
signed main(){
	freopen("trade.in","r",stdin);
	freopen("trade.out","w",stdout);
	// ios::sync_with_stdio(false);
	// cin.tie(0); cout.tie(0);
	n=read();
	int sum=1;
	For(i,1,n){
		a[i]=read();
		sum=min(1000001ll,sum*(a[i]+1));
	}
	int flag=0;
	For(i,1,n){
		if(a[i]>1) flag=1;
	}
	if(!flag){
		int p=1;
		For(i,1,n)p*=a[i];
		printf("%lld\n",p);
		return 0; 
	}
	if(n<=30&&sum<=1000000){
		dfs(1);
		printf("%lld\n",ans);
		return 0;
	}
#ifdef LOCAL
    Debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

